﻿// Copyright Microsoft

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Activities.Presentation.Model;
using Microsoft.Samples.SqlServer.ExtensionMethods;
using System.Activities.Statements;
using System.Collections.ObjectModel;
using System.Activities;
using Microsoft.Samples.SqlServer.Activities.Designers.OData;
using Microsoft.VisualBasic.Activities;

namespace Microsoft.Samples.SqlServer.Activities
{
    // Interaction logic for EntityPropertiesDesigner.xaml
    public partial class EntityPropertiesDesigner
    {
        public EntityPropertiesDesigner()
        {
            InitializeComponent();
        }

        /// <summary>
        /// Auto-assign EntityProperties
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void ActivityDesigner_Loaded(object sender, RoutedEventArgs e)
        {          
            //NOTE: The sample assumes a EntityProperties activity variable as IEnumerable<IEnumerable<EntityProperty>>            
            Sequence rootSequence = this.ModelItem.RootSequence() as Sequence;
            if (rootSequence != null)
            {
                var variable = (from v in rootSequence.Variables where v.Name == "EntityProperties" select v).First();
                this.ModelItem.Properties["Properties"].ComputedValue = new InArgument<Object>() { Expression = variable };
            }
        }
    }
}
